function fn(url) {
  let index = url.indexOf('?');
  console.log(index);
  let str = url.slice(index+1);
  console.log(str);
  const obj = {};
  const arr = str.split('&');
  console.log(arr);
  for (let i = 0; i < arr.length; i++) {
    let array = arr[i].split('=');
    if (obj[array[0]]) {
      obj[array[0]] = [].concat(obj[array[0]], array[1]);
    } else {
      obj[array[0]] = array[1];
    }
  }
  return obj;
}

let url = 'https://example.com?a=1&a=2&b=3';

console.log(fn(url));